<?php

namespace App\Http\Controllers\Guard\Site;

use App\Http\Controllers\Common\GuardController;
use App\Models\Site\Setting;
use Illuminate\Http\Request;

class SettingController extends GuardController
{
    public function index(Request $request) {
        if($request->isMethod('GET')){
            $records = Setting::get(['id','key','val','description']);
            return responseSuccess($records->toArray());
        }else{
            $info = $request->input('settings');
            foreach ($info as $item) {
                Setting::updateOrCreate(['key'=>$item['key']??0],[
                    'key'=>$item['key'],
                    'val'=>$item['val'],
                    'description'=>$item['description'],
                ]);
            }
            return responseSuccess();
        }
    }
}
